package com.itcs.app.tran;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSON;
import com.itcs.box.BoxConstants;
import com.itcs.box.domain.BoxResponse;
import com.itcs.box.util.LogUtils;

@Component
public class SendBoxSocket {
	private Logger logger = Logger.getLogger(SendBoxSocket.class);// 下发日志

	@Autowired
	private StringRedisTemplate stringRedisTemplate;

	/**
	 * 发布订阅方式 调用boxServer返回消息到通讯盒
	 * 
	 * @param response
	 */
	public void pubsubRes2BoxServer(BoxResponse response) {
		String jsonString = JSON.toJSONString(response);
		logger.info(LogUtils.build(response.getMessgeType(), "发送通讯盒广播", "通讯盒:" + response.getData().getDeviceId(),
				jsonString));
		stringRedisTemplate.convertAndSend(BoxConstants.PUBSUB_BOX_CHANNEL, jsonString);
	}
}
